import 'package:flutter/material.dart';
import 'package:fluttertoast/fluttertoast.dart';
import 'package:get/get.dart';
import 'package:xin_nuo_pda/base/BaseController.dart';
import 'package:xin_nuo_pda/bean/lot_entity.dart';
import 'package:xin_nuo_pda/http/api/lot_api.dart';
import 'package:xin_nuo_pda/http/api/qa_api.dart';

import '../bean/lot_id_entity_entity.dart';
import 'QcTrackInState.dart';

class QcTrackInController extends BaseController {
  final QcTrackInState state = QcTrackInState();
  LotEntity? lotEntity;
  String lotInfoId = "lotInfoId";
  String lotID = "";

  lotInfo() async {
    // update([lotInfoId]);
    Map<String, dynamic> params = {'LOTID': lotID};
    var result = await LotApi.lotInfo(canelToken, params: params);
    if (result.ok) {
      lotEntity = result.data;
      update([lotInfoId]);
    }
  }

  trackIn() async {
    if (lotID.isEmpty) {
      Get.snackbar('提示', "请先扫描批次号",
          colorText: Colors.white, backgroundColor: Colors.black87);
      return;
    }

    List<LotIdEntity> data = [];
    LotIdEntity info = LotIdEntity();
    info.lOTID = lotID;
    data.add(info);
    Map<String, dynamic> params = {
      'ACTIONTYPE': "DefaultTrackIn",
      'LOTLIST': data
    };
    var result = await QaApi.oqcTrackIn(canelToken, params: params);
    if (result.ok) {
      Fluttertoast.showToast(
        msg: "进站成功",
        toastLength: Toast.LENGTH_SHORT,
        gravity: ToastGravity.CENTER,
        timeInSecForIosWeb: 1,
      );
      Get.back();
    }
  }
}
